package xjtu.se.articlecommunity.buser.home;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xjtu.se.articlecommunity.common.CommonService;
import xjtu.se.articlecommunity.common.Result;
import xjtu.se.articlecommunity.common.TokenUtils;
import xjtu.se.articlecommunity.common.dto.CurrentUser;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/buser/home")
public class BhomeAPI {
    @Resource
    private CommonService commonService;

    @GetMapping("/curr-user")
    public Result getCurrUser(@RequestHeader("Token") String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token,commonService);
        return Result.success(currentUser);
    }

    @DeleteMapping("/exit")
    public Result exit(@RequestHeader("Token") String token){
        log.info("curr-buser has exited");
        TokenUtils.removeToken(token);
        return Result.success();
    }
}
